package com.hq.fxh.No6UerSpace.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hq.fxh.Modle.GetMyPostModle;
import com.hq.fxh.Modle.UserPlateModel;
import com.hq.fxh.R;
import com.hq.fxh.Utils.Tool;

import java.util.List;

import static cn.jpush.android.api.JPushInterface.a.n;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/9/19
 * @Email xlwenhao1858@sina.com
 */


public class Radapter_UserSpace_Plate extends RecyclerView.Adapter<Radapter_UserSpace_Plate.PlateViewHolder> {

    List<UserPlateModel> data;
    Context context;
    String name = "Radapter_UserSpace_Plate";

    public void setData(List<UserPlateModel> data) {
        this.data = data;
    }

    @Override
    public PlateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();

        PlateViewHolder plateViewHolder = new PlateViewHolder(View.inflate(context, R.layout.item_space_plate, null));


        return plateViewHolder;
    }

    @Override
    public void onBindViewHolder(PlateViewHolder holder, int position) {

        int itemViewType = getItemViewType(position);

        if (itemViewType == 0) {
            holder.layoutPic.setVisibility(View.GONE);

        } else {
            holder.layoutPic.setVisibility(View.VISIBLE);
            Tool.setUrlToImage(context, data.get(position).getTitle_pic().get(0), holder.newImageView);
        }


        Tool.setStringToText(holder.textTitle, data.get(position).getTitle());
        Tool.setStringToText(holder.tvPlateitemName, data.get(position).getCategory_name());
        Tool.setIntToText(holder.readNewNum, data.get(position).getNum_read(), name);

    }

    @Override
    public int getItemViewType(int position) {
        if (data != null) {
            List<String> title_pic = data.get(position).getTitle_pic();
            if (title_pic == null || title_pic.size() == 0) {
                return 0;
            } else {
                return 1;
            }

        } else {
            return 0;
        }

    }

    @Override
    public int getItemCount() {

        if (data == null) {
            return 0;
        } else {
            return data.size();
        }
    }


    class PlateViewHolder extends RecyclerView.ViewHolder {
        protected TextView textTitle;
        protected TextView readNewNum;
        protected ImageView newImageView;
        protected ImageView imageItemVideoTag;
        protected LinearLayout layoutPic;
        protected LinearLayout newsType1;
        private TextView tvPlateitemName;

        public PlateViewHolder(View itemView) {
            super(itemView);
            initView(itemView);
        }


        private void initView(View rootView) {
            textTitle = (TextView) rootView.findViewById(R.id.text_title);
            tvPlateitemName = (TextView) rootView.findViewById(R.id.tv_plateitem_name);
            readNewNum = (TextView) rootView.findViewById(R.id.readNewNum);
            newImageView = (ImageView) rootView.findViewById(R.id.new_imageView);
            imageItemVideoTag = (ImageView) rootView.findViewById(R.id.image_Item_VideoTag);
            layoutPic = (LinearLayout) rootView.findViewById(R.id.layout_Pic);
            newsType1 = (LinearLayout) rootView.findViewById(R.id.newsType1);
        }
    }


}
